<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1. <封装函数>转换数组
        const input = {
            shengjian: '生煎',
            baozi: '灌汤包',
            jiaozi: '水饺',
            burger: '汉堡',
        };
        const output = [
            {
                label: '生煎',
                value: 'shengjian',
            },
            {
                label: '灌汤包',
                value: 'baozi',
            },
            {
                label: '水饺',
                value: 'jiaozi',
            },
            {
                label: '汉堡',  
                value: 'burger',
            },
        ];
        // function transform(obj) {
        //     const res = [];
        //     for (const key in obj) {
        //         const tmp = {
        //             lable: obj[key],
        //             value: key,
        //         }
        //         res.push(tmp);
        //     }
        //     return res;
        // }
        // console.log(transform(input));

        // ⭐
        function transform1 (obj) {
           return Object.keys(obj).map(key => ({ label: obj[key], value: key}));
        }
        console.log(transform1(input));
    </script>
</body>

</html>